package com.school.controller;

import com.school.entity.Student;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.HashMap;

@RestController
@Slf4j
@RequiredArgsConstructor
public class SchoolController {

    public static final String GET_USERINFO_URL = "http://localhost:8081/one/{id}";

    private final RestTemplate restTemplate;

    @GetMapping("/sone/{id}")
    public Object getOne(@PathVariable Integer id){
        HashMap<String,Object> map = new HashMap<>();
        log.info("SchoolController.getOne:{}",id);
        Student student = this.restTemplate.getForObject(GET_USERINFO_URL, Student.class, id);
        map.put("code",334);
        map.put("data",student);
        return map;
    }
}
